/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    int maxDeep = 1;
    public int maxDepth(TreeNode root) {
        if(root == null) return 0;
        int deep = 1;
        def(root,deep);
        return maxDeep;
    }

    public void def(TreeNode root,int deep) {
        if(root == null) {
            return;
        }
        maxDeep = Math.max(maxDeep,deep);
        def(root.left,deep+1);
        def(root.right,deep+1);
    }
}